package com.adinnet.admin.address.service.impl;

import com.adinnet.admin.address.model.Address;
import com.adinnet.admin.address.mapper.AddressMapper;
import com.adinnet.admin.address.service.AddressService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 省市区 服务实现类
 * </p>
 *
 * @author zYshuai
 * @since 2020-12-17
 */
@Service
public class AddressServiceImpl extends ServiceImpl<AddressMapper, Address> implements AddressService {


    @Autowired
    private AddressMapper addressMapper;

    /**
     * @param code:编码
     * @param type:   类型 1 查询市  2 查询区
     * @Description: 省下的市, 或市下的区
     * @author zYshuai
     * @Date: 2020/12/17 9:55
     * @return: java.util.List<com.adinnet.admin.address.model.Address>
     */
    @Override
    public List<Address> addressList(String code, Integer type) {
        if (1 == type) {
            return addressMapper.selectList(new QueryWrapper<Address>().eq("type", 2).eq("deleted", 0).eq("province_code", code));
        }
        if (2 == type) {
            return addressMapper.selectList(new QueryWrapper<Address>().eq("type", 3).eq("deleted", 0).eq("city_code", code));

        }
        return Lists.newArrayList();
    }
}
